package Demo8;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();       //行数
        int m = sc.nextInt();       //列数
        int k = sc.nextInt();       //步数
        int[][] array = new int[n][m];

        int x = 0;
        int y = 0;      //最大数的坐标


        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                array[i][j] = sc.nextInt();
            }
        }
        for (int i = 0; i < k; i++) {   //步数
            int max = 0;
            for (int j = 0; j < n; j++) {//找最大
                for (int l = 0; l < m; l++) {
                    if (array[j][l] > max){
                        max = array[j][l];
                        x = j;
                        y = l;
                    }
                }
            }
            //轰炸
            //行操作
            for (int j = x+1; j < n; j++) {
                for (int l = 0; l < m; l++) {
                    array[j-1][l] = array[j][l];
                }
            }
            //列操作
            for (int j = 0; j < m - y; j++) {
                for (int l = y; l < n ; l++) {
                    array[j][l] = array[j][l+1];
                }
            }
            n--;
            m--;
        }

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                System.out.print(array[i][j]);
                if (j != m-1){
                    System.out.print(" ");
                }
            }
            System.out.println();
        }
    }
}
